<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--      &lt;!&ndash;部门数据&ndash;&gt;
            <el-col :span="4" :xs="24">
              <div class="head-container">
                <el-input
                  v-model="deptName"
                  placeholder="请输入部门名称"
                  clearable
                  size="small"
                  prefix-icon="el-icon-search"
                  style="margin-bottom: 20px"
                />
              </div>
              <div class="head-container">
                <el-tree
                  :data="deptOptions"
                  :props="defaultProps"
                  :expand-on-click-node="false"
                  :filter-node-method="filterNode"
                  ref="tree"
                  default-expand-all
                  @node-click="handleNodeClick"
                />
              </div>
            </el-col>-->
      <!--用户数据-->
      <el-col :span="20" :xs="24" style="width: 100%;">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="文档名称" prop="name">
            <el-input
              v-model="queryParams.file_title"
              placeholder="请输入文档名称"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="文档内容" prop="status">
            <el-input
              v-model="queryParams.file_content"
              placeholder="请输入文档内容"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8" v-show="false">
          <!--<el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['monitor:issue:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['monitor:issue:edit']"
            >修改</el-button>
          </el-col>-->
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['monitor:issue:remove']"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" ></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="channelList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="文档编号" align="center" key="file_id" prop="file_id"  />
          <el-table-column label="文档名称" align="center" key="file_title" prop="file_title"  />
          <el-table-column label="所属频道" align="center" key="channel_name" prop="channel_name"  />
          <el-table-column width="100" label="文档状态" align="center">
          <template slot-scope="scope">
            <el-link effect="dark"  v-if="scope.row.status==2">评审通过</el-link>
          <el-link type="success" effect="dark"  v-if="scope.row.status==4">待发布</el-link>
          <el-link type="warning" effect="dark"  v-if="scope.row.status==5">已发布</el-link>
          </template>
          </el-table-column>
          <el-table-column label="创建人" align="center" key="create_by" prop="create_by" />
          <el-table-column label="创建时间" align="center" prop="create_time" >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.create_time) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['monitor:issue:show']"
              >预览</el-button>
              <el-button
                v-if="scope.row.userId !== 1"
                size="mini"
                type="text"
                icon="el-icon-guide"
                @click="handleDelete(scope.row)"
                v-hasPermi="['monitor:issue:issue']"
              >发布</el-button>
              <el-button
                size="mini"
                type="text"
                @click="showVersions(scope.row)"
                v-hasPermi="['monitor:issue:annul']"
              >撤稿</el-button>
              <!--<el-button
                size="mini"
                type="text"
                icon="el-icon-key"
                @click="handleResetPwd(scope.row)"

              >重置</el-button>-->
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="频道名称" prop="name">
              <el-input v-model="form.channel_name" placeholder="请输入频道名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--<el-form-item label="归属部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
            </el-form-item>-->
            <el-form-item label="频道站点" prop="deptId">
              <el-input v-model="form.channel_site" placeholder="请输入频道站点" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="父频道">
              <el-select v-model="form.parent_id" placeholder="请选择">
                <!--<el-option

                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>-->
                <el-option
                  v-for="item in Options"
                  :key="item.channel_id"
                  :label="item.channel_name"
                  :value="item.channel_id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="item in status"
                  :key="item.dict_value"
                  :label="item.dict_value"
                >{{item.dict_label}}</el-radio>

              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>



      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>


  import { listFile , getFile , addFile , updateFile ,repealFile ,listFileEdit ,getFileIssueList ,issueFile} from "@/api/monitor/file";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
    name: "File",
    components: { Treeselect },
    data() {
      return {
        user: {},
        sexs: [],

        id_card_type: [],
        status:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户表格数据
        channelList: null,
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        // 是否显示弹出层
        open: false,
        // 部门名称
        deptName: undefined,
        // 默认密码
        initPassword: undefined,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        // 性别状态字典
        Options: [],
        // 岗位选项
        postOptions: [],
        // 角色选项
        roleOptions: [],
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,

        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: undefined,
          status: undefined,
          fileIds:undefined,
        },
/*        // 表单校验
        rules: {
          userName: [
            { required: true, message: "用户名称不能为空", trigger: "blur" }
          ],
          nickName: [
            { required: true, message: "用户昵称不能为空", trigger: "blur" }
          ],

          email: [
            {
              type: "email",
              message: "'请输入正确的邮箱地址",
              trigger: ["blur", "change"]
            }
          ],
          phonenumber: [
            {
              pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
              message: "请输入正确的手机号码",
              trigger: "blur"
            }
          ]
        }*/
      };
    },
    created() {
      this.getList();

      /*this.getDicts("sys_normal_disable").then(response => {
        this.statusOptions = response.data;
      });
      this.getDicts("sys_user_sex").then(response => {
        this.sexOptions = response.data;
      });
      this.getConfigKey("sys.user.initPassword").then(response => {
        this.initPassword = response.msg;
      });*/
    },

    methods: {
      /** 查询用户列表 */
      getList() {
        this.loading = true;
        getFileIssueList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.channelList = response.data.items;
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },

      getParentChannel(){
        getParentChannel().then(response =>{
          this.Options = response.data.items;
        })

      },

      /** 查询部门下拉树结构 */
      /*getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },*/
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.deptId = data.id;
        this.getList();
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          userId: undefined,
          deptId: undefined,
          userName: undefined,
          nickName: undefined,
          password: undefined,
          phonenumber: undefined,
          email: undefined,
          sex: undefined,
          status: "0",
          remark: undefined,
          postIds: [],
          roleIds: []
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.file_id);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {

        this.$router.push('/monitor/readAndEdit/add');

      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        /*this.getTreeselect();*/
        const fileId = row.file_id || this.ids;
        getFile(fileId).then(rs =>{
          if (rs.data.link!=null){
            window.open('http://vsadmin.shooknet.com:86/news/detail?vsid=' + fileId);
           /* window.open(rs.data.link)*/
          }else {
            let routeData = this.$router.resolve({
              /*path: '/monitor/issue/preview/'+fileId,*/
              path:'http://vsadmin.shooknet.com:86/news/detail?vsid=' + fileId
            });
            window.open('http://vsadmin.shooknet.com:86/news/detail?vsid=' + fileId);
          }
        })
      },
      /*历史版本*/
      showVersions(row){
        const fileIds = row.file_id || this.ids;
        this.form.fileIds = fileIds;
        this.$confirm('是否确认撤销文档编号为"' + fileIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {

          return repealFile(fileIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("撤稿成功");
        })
      },

      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.channel_id != undefined) {
              updateChannel(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addChannel(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const fileIds = row.file_id || this.ids;
        this.form.fileIds = fileIds;
        this.$confirm('是否确认发布文档编号为"' + fileIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {

          return issueFile(fileIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("发布成功");
        })
      },





    }

  };
</script>
